// #ifdef APP-PLUS
const isIos = plus.os.name === "iOS";
// #endif

/** 跳转到**应用**的权限页面 */
const goAppPermissionSetting = () => {
  if (isIos) {
    const permissionObj = uni.requireNativePlugin("LuanQing-Permission");
    permissionObj.gotoPermissionSettingPage();
    // 下列代码在iOS18的设备上无法跳转，故暂时注释不予适用，仅供后续参考
    // const UIApplication = plus.ios.import('UIApplication');
    // const application2 = UIApplication.sharedApplication();
    // const NSURL2 = plus.ios.import('NSURL');
    // const setting2 = NSURL2.URLWithString('app-settings:');
    // application2.openURL(setting2);
    // plus.ios.deleteObject(setting2);
    // plus.ios.deleteObject(NSURL2);
    // plus.ios.deleteObject(application2);
  } else {
    const Intent = plus.android.importClass("android.content.Intent");
    const Settings = plus.android.importClass("android.provider.Settings");
    const Uri = plus.android.importClass("android.net.Uri");
    const mainActivity = plus.android.runtimeMainActivity();
    const intent = new Intent();
    intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
    const uri = Uri.fromParts("package", mainActivity.getPackageName(), null);
    intent.setData(uri);
    mainActivity.startActivity(intent);
  }
};

/** 开启Android系统的设备服务GPS */
const openAndroidGPS = () => {
  const main = plus.android.runtimeMainActivity();
  const Intent = plus.android.importClass("android.content.Intent");
  const Settings = plus.android.importClass("android.provider.Settings");
  const intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
  main.startActivity(intent); // 打开系统设置GPS服务页面
};

/** 开启IOS系统的设备服务GPS */
const openIOS_GPS = () => {
  const UIApplication = plus.ios.import("UIApplication");
  const application2 = UIApplication.sharedApplication();
  const NSURL2 = plus.ios.import("NSURL");
  const setting2 = NSURL2.URLWithString("app-settings:");
  application2.openURL(setting2);
  plus.ios.deleteObject(setting2);
  plus.ios.deleteObject(NSURL2);
  plus.ios.deleteObject(application2);
};

/** 跳转系统设置gps页面 */
const goSystemGPSSetting = () => {
  if (isIos) {
    openIOS_GPS();
  } else {
    openAndroidGPS();
  }
};

export { goAppPermissionSetting, goSystemGPSSetting };
